package com.singletonapps.evory.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import com.singletonapps.evory.dto.MaterialDto;

@Entity
@Table(name = "MATERIAL")
public class Material implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -9168419556755174268L;

	@Id
	@SequenceGenerator(name="material_seq", sequenceName="SEQ_MATERIAL_ID", allocationSize=1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "material_seq")
	@Column(name = "id")
	private Long id;
	
	@ManyToOne
	@JoinColumn(name = "COURSE_ID")
	private Course cursoMaterial;
	
	@Column(name = "MATERIAL_NAME")
	private String nombre;
	
	@Column(name = "MATERIAL_DESC")
	private String descripcion;
	
	@Column(name = "MATERIAL_PATH")
	private String materialPath;
	
	@Column(name = "DATE_CREATE", nullable = false)
	private Date dateCreated;
	
	@Column(name = "DATE_UPDATE")
	private Date dateUpdated;
	
	@Version
	private int version;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Course getCurso() {
		return cursoMaterial;
	}

	public void setCurso(Course curso) {
		this.cursoMaterial = curso;
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getDescripcion() {
		return descripcion;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	public String getMaterialPath() {
		return materialPath;
	}

	public void setMaterialPath(String materialPath) {
		this.materialPath = materialPath;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	public Date getDateUpdated() {
		return dateUpdated;
	}

	public void setDateUpdated(Date dateUpdated) {
		this.dateUpdated = dateUpdated;
	}

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}
	
	public MaterialDto toDto(){
		
		MaterialDto dto = new MaterialDto();
		dto.setId(this.id);
		//dto.setCursoMaterial(this.cursoMaterial.toDto());
		dto.setNombre(this.nombre);
		dto.setDescripcion(this.descripcion);
		dto.setMaterialPath(this.materialPath);
		dto.setDateCreated(this.dateCreated);
		dto.setDateUpdated(this.dateUpdated);
		dto.setVersion(this.version);
		
		return dto;
	}
	
	
}
